package com.ruoyi.web.controller.personnel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.domain.IntervieweeInfo;
import com.ruoyi.personnel.vo.IntervieweeInfoVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.personnel.service.IIntervieweeInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import java.util.List;

/**
 * 受访人信息Controller
 *
 * @author wcq
 * @date 2020-03-02
 */
@Controller
@RequestMapping("/wx/user")
public class IntervieweeInfoController extends BaseController {

    private String prefix = "personnel/intervieweeInfo";

    @Autowired
    private IIntervieweeInfoService intervieweeInfoService;

    /**
     * 查询受访人姓名接口
     * @param intervieweeInfoVO
     * @return 响应信息
     */
    @PostMapping("/intervieweeInfo")
    @ResponseBody
    public AjaxResult selectIntervieweeName(@Validated @RequestBody IntervieweeInfoVO intervieweeInfoVO){
        return intervieweeInfoService.selectIntervieweeListByPhone(intervieweeInfoVO);
    }

    @RequiresPermissions("personnel:intervieweeInfo:view")
    @GetMapping()
    public String intervieweeInfo()
    {
        return prefix + "/intervieweeInfo";
    }

    /**
     * 查询受访人信息列表
     */
    @RequiresPermissions("personnel:intervieweeInfo:list")
    @PostMapping("personnel/intervieweeInfo/list")
    @ResponseBody
    public TableDataInfo list(IntervieweeInfo intervieweeInfo)
    {
        startPage();
        List<IntervieweeInfo> list = intervieweeInfoService.selectIntervieweeInfoList(intervieweeInfo);
        return getDataTable(list);
    }

    /**
     * 导出受访人信息列表
     */
    @RequiresPermissions("personnel:intervieweeInfo:export")
    @Log(title = "受访人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IntervieweeInfo intervieweeInfo)
    {
        List<IntervieweeInfo> list = intervieweeInfoService.selectIntervieweeInfoList(intervieweeInfo);
        ExcelUtil<IntervieweeInfo> util = new ExcelUtil<IntervieweeInfo>(IntervieweeInfo.class);
        return util.exportExcel(list, "intervieweeInfo");
    }

    /**
     * 新增受访人信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存受访人信息
     */
    @RequiresPermissions("personnel:intervieweeInfo:add")
    @Log(title = "受访人信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IntervieweeInfo intervieweeInfo)
    {
        return toAjax(intervieweeInfoService.insertIntervieweeInfo(intervieweeInfo));
    }

    /**
     * 修改受访人信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IntervieweeInfo intervieweeInfo = intervieweeInfoService.selectIntervieweeInfoById(id);
        mmap.put("intervieweeInfo", intervieweeInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存受访人信息
     */
    @RequiresPermissions("personnel:intervieweeInfo:edit")
    @Log(title = "受访人信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IntervieweeInfo intervieweeInfo)
    {
        return toAjax(intervieweeInfoService.updateIntervieweeInfo(intervieweeInfo));
    }

    /**
     * 删除受访人信息
     */
    @RequiresPermissions("personnel:intervieweeInfo:remove")
    @Log(title = "受访人信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(intervieweeInfoService.deleteIntervieweeInfoByIds(ids));
    }
}
